import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;
import java.util.Scanner;


public class Singnal_Anasis {
    public Singnal_Anasis() {
    };

    public static int N;
    public int getN(){
        return N;
    }

    public static void main(String[] args) throws JMSException {
        String brokerURL = "tcp://localhost:61616";
        ConnectionFactory factory = null;
        Connection connection = null;
        Session session = null;
        Topic topic1 = null;
        Topic topic2 = null;
        MessageConsumer messageConsumer = null;
//        Message message_ave = null;
//        Message message_me = null;
//        Message message_max = null;
//        Message message_min = null;
//        Message message_list = null;

        Message message_all = null;

        System.out.println("请输入一次传送数据包的大小：");
        Object[] all_message = new Object[5];

        try {
            factory = new ActiveMQConnectionFactory(brokerURL);
            connection = factory.createConnection();
            connection.start();
            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            topic1 = session.createTopic("Random_plot");
            topic2 = session.createTopic("Random_plot_package");
            messageConsumer = session.createConsumer(topic1);
            Scanner in = new Scanner(System.in);

            N = in.nextInt();
            MyListener listener = new MyListener();
            listener.Nequal(N);
            messageConsumer.setMessageListener(listener);
//            System.out.println(ifpackage);
//            if (ifpackage) {
//                    System.out.println(listener.getcount());
//
////                message_ave = session.createObjectMessage(listener.getave());
////                message_me = session.createObjectMessage(listener.getme());
////                message_max = session.createObjectMessage(listener.getmax());
////                message_min = session.createObjectMessage(listener.getmin());
////                message_list = session.createObjectMessage(listener.getMsglist());
//
//
//                  5  all_message[0] = listener.getave();
//                    all_message[1] = listener.getme();
//                    all_message[2] = listener.getmax();
//                    all_message[3] = listener.getmin();
//                    all_message[4] = listener.getMsglist();
//                    System.out.println(all_message);
//                    message_all = session.createObjectMessage((Serializable) all_message);
//                    messageProducer.send(message_all);
//                }
//        } catch (Exception e){
//            e.printStackTrace();
        } catch (Exception e){
            e.printStackTrace();
        }
    }
}

